<template>
    <div class="main">
        <!-- 导航栏 -->
        <div>
            <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>新生报道管理></el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <!-- 表格 -->
        <div>
            <el-card class="box-card">
                <div>
                    <div style="float:left">
                        <el-button @click="addUser()" type="success">添加报道</el-button>
                        <el-select v-model="value" style="width:135px" placeholder="请选择">
                            <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                        <el-input v-model="value2" style="width:250px"></el-input>
                        <el-button @click="mohuchaxun()" type="success">查询</el-button>
                        <el-button type="success" @click="chongzhi()">重置</el-button>
                    </div>
                    <div style="float:right">
                        <el-button @click="daochu()" type="success">导出</el-button>
                    </div>
                <el-table
                :data="tableData"
                height="500px"
                stripe
                style="width: 100%">
                <el-table-column type="index"></el-table-column>
                <el-table-column prop="studentId" show-overflow-tooltip label="学号"></el-table-column>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="idCard" show-overflow-tooltip label="身份证号"></el-table-column>
                <el-table-column prop="candidateId" show-overflow-tooltip label="高考准考证号" width="110px"></el-table-column>
                <el-table-column prop="sex" label="性别"></el-table-column>
                <el-table-column prop="age" label="年龄"></el-table-column>
                <el-table-column prop="telephone" show-overflow-tooltip label="手机号"></el-table-column>
                <el-table-column prop="discipline" show-overflow-tooltip label="就读专业"></el-table-column>
                <el-table-column prop="className" show-overflow-tooltip label="所在班级"></el-table-column>
                <el-table-column prop="facultyName" show-overflow-tooltip label="所在学院"></el-table-column>
                <el-table-column prop="province" show-overflow-tooltip label="省份"></el-table-column>
                <el-table-column prop="address" show-overflow-tooltip label="详细地址"></el-table-column>
                <el-table-column prop="fname" show-overflow-tooltip label="父亲姓名"></el-table-column>
                <el-table-column prop="ftelephone" show-overflow-tooltip label="父亲手机号" width="100px"></el-table-column>
                <el-table-column prop="mname" show-overflow-tooltip label="母亲姓名"></el-table-column>
                <el-table-column prop="mtelephone" show-overflow-tooltip label="母亲手机号" width="100px"></el-table-column>
                <el-table-column prop="political" show-overflow-tooltip label="政治面貌"></el-table-column>
                <el-table-column prop="achievement" label="高考成绩"></el-table-column>
                <el-table-column prop="highSchool" show-overflow-tooltip label="就读高中"></el-table-column>
                <el-table-column prop="reginfo" label="报道情况">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.reportInfo=='是'">已报到</el-tag>
                        <el-tag type="danger" v-else>未报道</el-tag>
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="regTime" show-overflow-tooltip label="报到时间"></el-table-column>
                <el-table-column prop="notificationNumber" show-overflow-tooltip label="录取编号"></el-table-column> -->
                <!-- <el-table-column prop="modifiedTime" show-overflow-tooltip label="最后修改时间" width="110px"></el-table-column> -->
                <el-table-column prop="address" label="操作" fixed="right" width="100px">
                    <template slot-scope="scope">
                        <el-button @click="editData(scope.row)" type="text" size="small">编辑</el-button>
                        <el-button @click="deleteData(scope.row)" type="text" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            </div>
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="count"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
            </el-card>
            <!-- 编辑dialog -->
            <el-dialog
            title="编辑"
            :visible.sync="centerDialogVisible"
            width="45%"
            height="450px"
            center>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="姓名">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="form.idCard" ></el-input>
                </el-form-item>
                <el-form-item label="高考准考证号">
                    <el-input v-model="form.candidateId" ></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-input v-model="form.sex"></el-input>
                </el-form-item>
                <el-form-item label="年龄">
                    <el-input v-model="form.age"></el-input>
                </el-form-item>
                <el-form-item label="手机号码">
                    <el-input v-model="form.telephone" ></el-input>
                </el-form-item>
                <el-form-item label="就读专业">
                    <el-input v-model="form.discipline" ></el-input>
                </el-form-item>
                <el-form-item label="所在班级">
                    <el-input v-model="form.className" ></el-input>
                </el-form-item>
                <el-form-item label="所在学院">
                    <el-input v-model="form.facultyName"></el-input>
                </el-form-item>
                <el-form-item label="省份">
                    <el-input v-model="form.province"></el-input>
                </el-form-item>
                <el-form-item label="学号">
                    <el-input v-model="form.studentId" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="详细地址">
                    <el-input v-model="form.address"></el-input>
                </el-form-item>
                <el-form-item label="父亲姓名">
                    <el-input v-model="form.fname"></el-input>
                </el-form-item>
                <el-form-item label="父亲联系方式">
                    <el-input v-model="form.ftelephone"></el-input>
                </el-form-item>
                <el-form-item label="母亲姓名">
                    <el-input v-model="form.mname"></el-input>
                </el-form-item>
                <el-form-item label="母亲联系方式">
                    <el-input v-model="form.mtelephone"></el-input>
                </el-form-item>
                <el-form-item label="政治面貌">
                    <el-select v-model="form.political" placeholder="请选择">
                        <el-option label="党员" value="党员"></el-option>
                        <el-option label="团员" value="团员"></el-option>
                        <el-option label="群众" value="群众"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="高考成绩">
                    <el-input v-model="form.achievement" :disabled="true"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="commitData()">提 交</el-button>
            </span>
            </el-dialog>
            <!-- 导出dialog -->
            <el-dialog
            title="导出"
            :visible.sync="centerDialogVisible1"
            width="400px"
            height="450px"
            center>

            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible1 = false">取 消</el-button>
                <el-button type="primary" @click="commitData1()">导出</el-button>
            </span>
            </el-dialog>
            <!-- 添加用户dialog -->
            <el-dialog
            title="添加用户"
            :visible.sync="centerDialogVisible2"
            width="45%"
            height="450px"
            center>
            <el-form ref="form2" :model="form2" label-width="80px">
                <el-form-item label="姓名">
                    <el-input v-model="form2.name"></el-input>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="form2.idCard" ></el-input>
                </el-form-item>
                <el-form-item label="高考准考证号">
                    <el-input v-model="form2.candidateId" ></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-input v-model="form2.sex"></el-input>
                </el-form-item>
                <el-form-item label="年龄">
                    <el-input v-model="form2.age"></el-input>
                </el-form-item>
                <el-form-item label="手机号码">
                    <el-input v-model="form2.telephone" ></el-input>
                </el-form-item>
                <el-form-item label="就读专业">
                    <el-input v-model="form2.discipline" ></el-input>
                </el-form-item>
                <el-form-item label="所在班级">
                    <el-input v-model="form2.className" ></el-input>
                </el-form-item>
                <el-form-item label="所在学院">
                    <el-input v-model="form2.facultyName"></el-input>
                </el-form-item>
                <el-form-item label="省份">
                    <el-input v-model="form2.province"></el-input>
                </el-form-item>
                <el-form-item label="学号">
                    <el-input v-model="form2.studentId"></el-input>
                </el-form-item>
                <el-form-item label="详细地址">
                    <el-input v-model="form2.address"></el-input>
                </el-form-item>
                <el-form-item label="就读高中">
                    <el-input v-model="form2.highSchool"></el-input>
                </el-form-item>
                <el-form-item label="父亲姓名">
                    <el-input v-model="form2.fname"></el-input>
                </el-form-item>
                <el-form-item label="父亲联系方式">
                    <el-input v-model="form2.ftelephone"></el-input>
                </el-form-item>
                <el-form-item label="母亲姓名">
                    <el-input v-model="form2.mname"></el-input>
                </el-form-item>
                <el-form-item label="母亲联系方式">
                    <el-input v-model="form2.mtelephone"></el-input>
                </el-form-item>
                <el-form-item label="政治面貌">
                    <el-select v-model="form2.political" placeholder="请选择">
                        <el-option label="党员" value="党员"></el-option>
                        <el-option label="团员" value="团员"></el-option>
                        <el-option label="群众" value="群众"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="高考成绩">
                    <el-input v-model="form2.achievement"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible2 = false">取 消</el-button>
                <el-button type="primary" @click="commitData2()">添加</el-button>
            </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            tableData:[],
            total:10,
            page:1,
            count:10,
            centerDialogVisible:false,
            centerDialogVisible1:false,
            centerDialogVisible2:false,
            form:{},
            options:[
                {value:'0',label:'姓名'},
                {value:'1',label:'身份证号'},
                {value:'2',label:'学号'},
            ],
            value:'',
            value2:'',
            form2:{
                "achievement": "",//
                "address": "",//
                "age": "",//
                "candidateId": "",//
                "className": "",//
                "discipline": "",//
                "facultyName": "",//
                "fname": "",//
                "ftelephone": "",//
                "highSchool": "",//
                "idCard": "",//
                "mname": "",//
                "mtelephone": "",//
                "name": "",//
                "notificationNumber": "",
                "political": "",//
                "province": "",//
                "reginfo": "",
                "sex": "",//
                "studentId": '',//
                "telephone": ""//
            }
        }
    },
    methods:{
        getNewBornData(){
            var _this=this
            var url='http://taruinfo.work:8088/newborn/selectByPageCounnt?page='+_this.page+'&pageCount='+_this.count
            _this.$axios.get(url).then(function(res){
                // console.log(res.data)
                if(res.data.code='200'){
                  _this.total=res.data.total
                  _this.tableData=res.data.records
                }else{
                    console.log('获取宿舍信息失败')
                }
            })
        },
        handleSizeChange(val){
            this.count=val
            this.getNewBornData()
        },
        handleCurrentChange(val){
            this.page=val
            this.getNewBornData()
        },
        editData(row) {
            console.log(row)
            this.form=row
            this.centerDialogVisible=true
        },
        commitData(){
            var _this=this
            var url='http://taruinfo.work:8088/newborn/update'
            _this.$axios.put(url,_this.form).then(function(res){
                if(res.data.code==200){
                    _this.$message({
                      message: '更新成功',
                      type: 'success'
                    })
                    _this.centerDialogVisible=false
                    _this.getNewBornData()
                }else{
                   _this.$message({
                      message: '更新失败',
                      type: 'error'
                    })
                   _this.centerDialogVisible=false 
                }
            })
        },
        deleteData(row){
            var _this=this
            var url='http://taruinfo.work:8088/newborn/deleteByID?id='+row.id
            _this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                _this.$axios.delete(url).then(function(res){
                if(res.data.code==200){
                    _this.$message({
                        type: 'success',
                        message: '删除成功!'
                    })
                    _this.getNewBornData()
                }else{
                    _this.$message({
                        type: 'error',
                        message: '删除失败!'
                    })
                }
            })  
            }).catch(() => {
                _this.$message({
                    type: 'info',
                    message: '已取消删除'
                })         
            })
        console.log(row)
        },
        chongzhi(){
            this.getNewBornData()
        },
        mohuchaxun(){
            var _this=this
            var url1='http://taruinfo.work:8088/newborn/likeLeftNewbornByLists?current=1&name='+_this.value2+'&size=10'
            var url2='http://taruinfo.work:8088/newborn/likeLeftNewbornByLists?current=1&idCard='+_this.value2+'&size=10'
            var url3='http://taruinfo.work:8088/newborn/likeLeftNewbornByLists?current=1&size=10&studentId='+_this.value2
            if(_this.value2!=''){
                if(_this.value=='0'){
                    _this.$axios.get(url1).then(function(res){
                    console.log(res.data)
                    if(res.data.code =='200'){
                    _this.total=res.data.data.total
                    _this.tableData=res.data.data.records
                    _this.value=''
                    _this.value2=''
                    }else{
                        console.log('获取信息失败')
                    }
                })
                }else if(_this.value=='1'){
                    _this.$axios.get(url2).then(function(res){
                    console.log(res.data)
                    if(res.data.code =='200'){
                    _this.total=res.data.data.total
                    _this.tableData=res.data.data.records
                    _this.value=''
                    _this.value2=''
                    }else{
                        console.log('获取信息失败')
                    }
                })
                }else if(_this.value=='2'){
                    _this.$axios.get(url3).then(function(res){
                    console.log(res.data)
                    if(res.data.code =='200'){
                    _this.total=res.data.data.total
                    _this.tableData=res.data.data.records
                    _this.value=''
                    _this.value2=''
                    }else{
                        console.log('获取信息失败')
                    }
                })
                }else{

                }
            }else{
                _this.$message({
                    message: '条件不能为空',
                    type: 'warning'
                })
            }
        },
        daochu(){

        },
        addUser(){
            this.centerDialogVisible2=true
        },
        commitData2(){
            var _this=this
            var url='http://taruinfo.work:8088/newborn/insert'
            _this.$axios.post(url,_this.form2).then(function(res){
                if(res.data.code=='200'){
                    _this.$message({
                        message:'添加成功',
                        type:'success'
                    })
                    _this.centerDialogVisible2=false
                }else{
                    _this.$message({
                        message:'添加失败',
                        type:'error'
                    })
                }
            }).catch(()=>{
                console.log(res.data.message)
            })
        },
        commitData1(){
            this.centerDialogVisible1=true
        }
    },
    mounted(){

    },
    created(){
        this.getNewBornData()
    }
}
</script>

<style scoped>
.box-card{
    width: 1270px;
    height:615px;
    margin-top: 10px;
}
</style>